package converters;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import restcrud.entites.Department;
import restcrud.entites.Employee;

@Component
public class RmployeeConverter implements Converter<String, Employee> {

	/**
	 * 将admin-qwe@qq.com-1-101-D-AA转换为Employee
	 */
	@Override
	public Employee convert(String source) {
		String[] split = source.split("-");
		if(split!=null&&split.length==4) {
			Employee employee = new Employee();
			employee.setLastName(split[0]);
			employee.setEmail(split[1]);
			employee.setGender(Integer.valueOf(split[2]));
			Department department = new Department();
			department.setId(Integer.parseInt(split[3]));
			
			employee.setDepartment(department);
			System.out.println(source + "--convert--" + employee);
			return employee;
		}
		return null;
	}

}
